#include <iostream>
#include <cstdlib>
#include <windows.h>

void report_error_and_exit(const char *msg)
{
	MessageBox(0, msg, "Error", MB_ICONSTOP);
    std::exit(EXIT_FAILURE);
}

void report_error_and_exit(DWORD err)
{
    LPTSTR buf;
    
    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
        0,
        err,
        0,
        (LPTSTR)&buf,
        0,
        0
    );
    report_error_and_exit(buf);
}

void *load_rcdata(DWORD &size)
{
	HMODULE launcher = GetModuleHandle(0);
	LPSTR name       = MAKEINTRESOURCE(1);
	LPTSTR type      = MAKEINTRESOURCE(RT_RCDATA);
	HRSRC res        = FindResource(launcher, name, type);
	
	if(!res)
		report_error_and_exit("RCDATA not present");
	
	size           = SizeofResource(launcher, res);
	HGLOBAL handle = LoadResource(launcher, res);
	return           LockResource(handle);
}
